package com.singer.druid;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.singer.piping.Modify;
import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Properties;

public class SingerModify implements Modify {

    /**
     * 歌手的修改
     * @throws Exception
     */
    @Override
    public void delete(int id , String name, int age,String song) throws Exception {
        Properties prop = new Properties();

        prop.load(new FileInputStream("src/druid.properties"));

        DataSource data = DruidDataSourceFactory.createDataSource(prop);

        Connection connection = data.getConnection();

        String sql="update t_singer\n" +
                "set name=?,\n" +
                "age=?,\n"+
                "song=?\n"+
                "where id=?";
         PreparedStatement set= connection.prepareStatement(sql);

         set.setString(1,name);
        set.setInt(2,age);
        set.setString(3,song);
        set.setInt(4,id);

        int count=set.executeUpdate();
        if (count>0){
            System.out.println("修改成功！");
        }
        set.close();
        connection.close();



    }

    @Override
    public void delete1(int id, String name, int age) throws Exception {
        Properties prop = new Properties();
        prop.load(new FileInputStream("src/druid.properties"));

        DataSource data = DruidDataSourceFactory.createDataSource(prop);

        Connection connection = data.getConnection();

        String sql="update t_judge\n" +
                "set name=?,\n" +
                "age=?\n"+
                "where id=?";
        PreparedStatement set= connection.prepareStatement(sql);

        set.setString(1,name);
        set.setInt(2,age);
        set.setInt(3,id);

        int count=set.executeUpdate();
        if (count>0){
            System.out.println("修改成功！");
        }
        set.close();
        connection.close();

    }

}
